import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import path from 'path'

const host = process.env.TAURI_DEV_HOST

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    react({
      babel: {
        plugins: [['babel-plugin-react-compiler']],
      },
    }),
    tailwindcss(),
  ],
  base: './',
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
    }
  },
  server: {
    host,
    port: 1420,
    proxy: {
      // '/mock': {
      //   target: '',
      //   changeOrigin: true, // 是否跨域（选择 true）
      //   rewrite: (path: string) => path.replace(/^\/images/, ''), // 这里使用了正则表达式，表示传入的 path 参数 以 /images 开头的其中的 /images 会被删掉
      //   bypass(req: any, res: any, options: any) {
      //     //@ts-ignore
      //     const proxyUrl = new URL(options.rewrite(req.url) || '',(options.target)as string)?.href || ''
      //     req.headers['x-req-proxyUrl'] = proxyUrl
      //     res.setHeader('x-res-proxyUrl', proxyUrl)
      //   },
      // },
    },
    watch: {
      // 3. tell vite to ignore watching `src-tauri`
      ignored: ['**/src-tauri/**'],
    },
  },
  build: {
    outDir: 'dist',
    emptyOutDir: true
  }
})
